package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IMyCenterFragmentModel;
import com.wgts.wgts.mvp.presenter.IMyCenterFragmentPersenter;
import com.wgts.wgts.mvp.view.IMyCenterFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.AppUpdateEntity;
import com.wgts.wgts.netmodle.resp.MyCenterMessageEntity;
import com.wgts.wgts.rxjava.MVPResultSubscriber;
import com.wgts.wgts.tools.AppInfor;

/*
 *
 *
 *   data:2018/9/2918:51
 *
 */public class MyCenterFragmentPersenter implements IMyCenterFragmentPersenter{
     private IMyCenterFragmentView view;
     private IMyCenterFragmentModel model;

    public MyCenterFragmentPersenter(IMyCenterFragmentView view, IMyCenterFragmentModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void getMyCenterResult() {
        model.getMyCenterResult(new HttpResultSubscriber<MyCenterMessageEntity>() {
            @Override
            public void onSuccess(MyCenterMessageEntity entity) {
                AppInfor.getInstance().setVipFansCount(entity.vipFansCount);
                AppInfor.getInstance().setSvipFansCount(entity.svipFansCount);
                AppInfor.getInstance().setUserName(entity.userNickName);
                AppInfor.getInstance().setUserHead(entity.userImage);
                AppInfor.getInstance().setUserPhone(entity.userPhone);
                AppInfor.getInstance().setInviteCode(entity.userCode);
                AppInfor.getInstance().setwChart(entity.unionid);
                Integer userState = Integer.parseInt(entity.userRole);
                AppInfor.getInstance().setUserState(userState);
                AppInfor.getInstance().setModifyPayPassword(entity.modifyPayPassword);
                AppInfor.getInstance().setAvailableBalance(entity.availableBalance);
                AppInfor.getInstance().setIllegal(entity.illegal);
                view.getMyCenterResult(entity);
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void appUpdate(String channel, String version) {
        model.appUpdate(channel, version, new HttpResultSubscriber<AppUpdateEntity>() {
            @Override
            public void onSuccess(AppUpdateEntity appUpdateEntity) {
                view.appUpdate(appUpdateEntity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void quitLogin() {
        model.quitLogin(new MVPResultSubscriber<String>() {
            @Override
            public void netx(String s) {
                view.quitLogin();
            }
        });
    }
}
